package wang.conge.javasedemo.core.thread;
public class VolatileDemo {

	public static void main(String[] args) {
		Model model = new Model();
		
		new Thread(()->{
			try {
				Thread.sleep(1000);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			model.setFlag(false);
		}).start();
		
		
		new Thread(()->{
			while(model.isFlag()){
				System.out.println(model.isFlag());
			}
		}).start();
	}
	
	static class Model{
		private volatile boolean flag = true;

		public boolean isFlag() {
			return flag;
		}

		public void setFlag(boolean flag) {
			this.flag = flag;
		}
	}
}	
